package de.tuberlin.dima.dkey.tmp;

import java.util.regex.Pattern;

import de.tuberlin.dima.dkey.nodes.GNode;

public class RegexNode implements GNode{
	
	private static final long serialVersionUID = 1L;

	protected int id;
	protected int graph;
	final String type = "RegexNode";

	Pattern pattern = null;

	
	
	public RegexNode(){
		throw new UnsupportedOperationException(); 
	}
	
	public RegexNode(int graph, int id, String value){
		this.id = id;
		this.graph = graph;
		
		this.pattern = Pattern.compile(value);

		
	}
	
	public String getValue() {
		return pattern.toString();
	}

	public int getId() {
		return id;
	}

	public int getGraph() {
		return graph;
	}
	
	public String getType(){
		return type;
	}
	
	public String getColour(){
		return "red";
	}
	
	public boolean equals(GNode toEval) {
		if(toEval instanceof RegexNode ){
			System.err.println("You can not do Regex of Regex");
		}
		
		return this.pattern.matcher(toEval.getValue()).matches();
	}
	
	public boolean equalsIgnoreCase(GNode toEval) {
		if(toEval instanceof RegexNode){
			System.err.println("You can not do Regex of Regex");
		}
		
		this.pattern = Pattern.compile(this.pattern.pattern(), Pattern.CASE_INSENSITIVE );
		
		return this.pattern.matcher(toEval.getValue()).matches();
	}
	
	@Override public String toString() {
		return "r:" + id + ":" + pattern + ":" + graph;
	}
	
	/**
     * Returns the hash code value for this edge.
     *
     * @return the hash code value for this list
     */
    public int hashCode() {
        int hashCode = 1;
        
        hashCode = 31*hashCode + id;
        hashCode = 31*hashCode + pattern.hashCode();
        
        return hashCode;
    }
	
}
